﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using DataAccess;
using BusinessLogic;

namespace ATM_System_Mock1_G2
{
    public partial class ValidateCard : System.Web.UI.Page
    {
        CardEntites cardE = new CardEntites();
        CardDA CarD = new CardDA();
        CardBL carBL = new CardBL();
        string Block;
        protected void Page_Load(object sender, EventArgs e)
        {
           if(txt_CarNo.Text !="")
           {
               Session["CardNo"] = txt_CarNo.Text;
           }
           txt_CarNo.Focus();
           
        }

        protected void Button11_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txt_CarNo.Text))
            {
                lb_ThongBao.Text = "* CardNo is not null";
            }
            else
                if(txt_CarNo.Text.Length !=16)
                {
                    lb_ThongBao.Text = "* CardNo has 16 characters";
                }
            else
            {
                Check();
            }
            
        }
      
        public void Check()
        {
            try {
                
                cardE.CardNo = txt_CarNo.Text;
                if (carBL.kiemtra(cardE)==true)
                {
                    Block = Session["Block"].ToString();
                    if (Block == "Block")
                    {
                        lb_ThongBao.Text = " *CardNo is  Block";
                    }else{
                        Response.Redirect("ValidatePIN.aspx");
                    }
                    
                }
                else {
                    lb_ThongBao.Text = " *CardNo is not exist";
                }       
            }
            catch(Exception ex)
            {
                throw ex;
            }
                             
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CheckBalance.aspx");
        }

        protected void btn_12_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Transfer.aspx");
        }

        protected void btn_Num1_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 1;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 2;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 3;
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 4;
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 5;
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 6;
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 7;
        }

        protected void Button9_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 8;
        }

        protected void Button10_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 9;
        }

        protected void Button13_Click(object sender, EventArgs e)
        {
            txt_CarNo.Text += 0;
        }
       
    }
}